unit FormFuse;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  RzTabs,JvPlgIntf,FormParent;


procedure ShowCaption(ParentCtrl: TWinControl; ACaption: string);
procedure ShowDockForm(FormClass: TFormClass; dockCtrl: TWinControl;
  IsMaxed: Boolean);

implementation

procedure ShowCaption( ParentCtrl: TWinControl; ACaption: string);
begin
  if ParentCtrl is TRzTabSheet then
    TRzTabSheet(ParentCtrl).Caption := ACaption;
end;

procedure ShowDockForm(FormClass: TFormClass; dockCtrl: TWinControl;
  IsMaxed: Boolean);
var
  i: Integer;
  TabCtrl: TRzTabSheet;
  Form: TForm;
begin
  Screen.Cursor := crHourGlass;
  try
    for i := 0 to Screen.CustomFormCount - 1 do
      if Screen.CustomForms[i] is FormClass then
      begin
        if (not(Screen.CustomForms[i]).Visible) then
          (Screen.CustomForms[i]).Visible := True;
        (Screen.CustomForms[i]).BringToFront;
        (Screen.CustomForms[i]).SetFocus;
        TabCtrl := TRzTabSheet(Screen.CustomForms[i].Parent);
        ShowCaption(TabCtrl, Screen.CustomForms[i].Caption);
        TRzPageControl(dockCtrl).ActivePageIndex := TabCtrl.PageIndex;
        exit;
      end;

    TabCtrl := TRzTabSheet.Create(dockCtrl); // dockCtrl
    TabCtrl.PageControl := TRzPageControl(dockCtrl);
    TRzPageControl(dockCtrl).ActivePageIndex := TabCtrl.PageIndex;

    if IsMaxed then  TabCtrl.Tag:=10
    else TabCtrl.Tag:=20;

    Form := FormClass.Create(TabCtrl);
    with Form do
      try
        ManualDock(TabCtrl);
        ShowCaption(TabCtrl, Caption);
        Show;
        Form.WindowState := wsMaximized;
        Form.Align := alClient;
      except
        Free;
      end;

  finally
    Screen.Cursor := crDefault;
  end;
end;

end.
